# Create your views here.
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext 
from lab.seminars.models import Presentation, PresentationForm


def presentation_form(request, id=None):
    presentation = None
    if id is not None:
        presentation = Presentation.objects.get(id=id)
    if request.POST:
        form = PresentationForm(data=request.POST, instance=presentation)
        if form.is_valid():
	        new_presentation = form.save(commit=False)
            	new_presentation.presenter = request.user
       	 	new_presentation.save()
        #	form.save_m2m()
        	return HttpResponseRedirect('/seminars/')
    else:
        form = PresentationForm(instance = presentation)
        
    return render_to_response('seminars/presentation_form.html',{'form':form},context_instance=RequestContext(request))

